package org.clzps.filetransfer.ftp;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * Load the parameters of the ftp
 * @author Aries Chou 13/09/2011
 *
 */
public class FtpConfig {
	private final Logger logger = Logger.getLogger(getClass());
	
	private String fileName = "ftp-user.properties";

	public String getFileName() {
		return fileName;
	}

	public FtpConfigInfo getFtpInfo() {
		FtpConfigInfo ftpBean = new FtpConfigInfo();
		Properties properties = null;
		
		InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
		
		properties = new Properties();
		
		try {
			properties.load(in);
			ftpBean.setHostname(properties.getProperty("ftp.hostname"));
			ftpBean.setPort(Integer.parseInt(properties.getProperty("ftp.port", "21")));
			ftpBean.setUsername(properties.getProperty("ftp.username"));
			ftpBean.setPassword(properties.getProperty("ftp.password"));
			
			logger.info("Loading " + fileName + " Success!");
			
			in.close();
			return ftpBean;
		} catch (IOException e) {
			logger.error("Loading " + this.getFileName() + " Failed!");
		}
		return null;
	}
}
